﻿// <copyright file="IntegerOutOfRangeException.cs" company="SingularityShift">
// Copyright (c) 2009 SingularityShift.com
// </copyright>
// <author>Ben McClure</author>
// <email>ben@singularityshift.com</email>
// <date>2009-08-14</date>
// <summary>An exception to throw when an integer is outside of an allowed range.</summary>
namespace GameLib.Util
{
    using System;
    using System.Runtime.Serialization;
    using System.Security.Permissions;
    using System.Text;
    using System.Xml.Serialization;

    /// <summary>
    /// An exception that is thrown when a used/provided integer is out of a valid defined range.
    /// </summary>
    [Serializable()]
    public class IntegerOutOfRangeException : Exception
    {    
        /// <summary>
        /// Initializes a new instance of the IntegerOutOfRangeException class.
        /// </summary>
        public IntegerOutOfRangeException() : base()
        {
        }
        
        /// <summary>
        /// Initializes a new instance of the IntegerOutOfRangeException class, specifying only a message but no data about the integer.
        /// </summary>
        /// <param name="message">A message about the exception</param>
        public IntegerOutOfRangeException(string message) : base(message)
        {
        }
        
        /// <summary>
        /// Initializes a new instance of the IntegerOutOfRangeException class, specifying a message and an innerException of the same or another type.
        /// </summary>
        /// <param name="message">A message about the exception</param>
        /// <param name="innerException">An internal exception to include that provides additional context or information</param>
        public IntegerOutOfRangeException(string message, Exception innerException) : base(message, innerException)
        {
        }
        
        /// <summary>
        /// Initializes a new instance of the IntegerOutOfRangeException class, specifying the value that was given as out of range.
        /// </summary>
        /// <param name="value">The value which is out-of-range</param>
        public IntegerOutOfRangeException(int value) : base("Given integer (" + value + ") out of allowed range")
        {
            this.Value = value;
        }

        /// <summary>
        /// Initializes a new instance of the IntegerOutOfRangeException class, specifying the given value and the lower and upper range of integers allowed.
        /// </summary>
        /// <param name="value">The value which is out-of-range</param>
        /// <param name="minimum">The lowest allowed integer in the range</param>
        /// <param name="maximum">The highest allowed integer in the range</param>
        public IntegerOutOfRangeException(int value, int minimum, int maximum) : base("Given integer (" + value + ") out of allowed range (" + minimum + " to " + maximum + ")")
        {
            this.Value = value;
            this.Minimum = minimum;
            this.Maximum = maximum;
        }
        
        /// <summary>
        /// Initializes a new instance of the IntegerOutOfRangeException class, used for serialization
        /// </summary>
        /// <param name="info">Serialization information</param>
        /// <param name="context">Context for serialization</param>
        protected IntegerOutOfRangeException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
        }

        /// <summary>
        /// Gets or sets the provided integer value which is out-of-range
        /// </summary>
        public int Value
        {
            get;
            protected set;
        }

        /// <summary>
        /// Gets or sets the minimum value in the range
        /// </summary>
        public int Minimum
        {
            get;
            protected set;
        }

        /// <summary>
        /// Gets or sets the maximum value in the range
        /// </summary>
        public int Maximum
        {
            get;
            protected set;
        }
        
        /// <summary>
        /// Formats and gets object data for serialization
        /// </summary>
        /// <param name="info">Serialization information</param>
        /// <param name="context">Context for serialization</param>
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
        }
    }
}